# -*- coding: utf-8 -*-
# ----------------------------
# @Time    : 2022/5/29 8:27 PM
# @Author  : changqingai
# @FileName: 07-load_set_data.py
# ----------------------------

import os
import tensorflow as tf

file_paths = [
    "./datasets/1.text", "./datasets/2.text"]

list_ds = tf.data.Dataset.list_files(file_paths)

for name in list_ds.take(3):
    print(name.numpy())


def parse_path(file_path):
    label = tf.strings.split(tf.strings.split(file_path, os.sep)[-1], ".")[0]
    # print(label.numpy())
    # print(tf.strings.split(file_path, os.sep).numpy())
    return tf.io.read_file(file_path), label


data_ds = list_ds.map(parse_path)
for data, label in data_ds.take(3):
    print("data:", label.numpy(), data.numpy())
